﻿using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;

namespace ThunderboltCustomControlLibrary;
/// <summary>头部带下拉框的文本框 </summary>
public class HeadOptionalTextBox:TextBox
{
	static HeadOptionalTextBox()
	{
		DefaultStyleKeyProperty.OverrideMetadata(typeof(HeadOptionalTextBox), new FrameworkPropertyMetadata(typeof(HeadOptionalTextBox)));
	}
	/// <summary>提示文本 </summary>
	[CategoryAttribute("Custom attribute"), DescriptionAttribute("Gets or sets the default text")]
	public string PlaceHolder
	{
		get { return (string)GetValue(PlaceHolderProperty); }
		set { SetValue(PlaceHolderProperty, value); }
	}
	[CategoryAttribute("Custom attribute"), DescriptionAttribute("Gets or sets the default text")]
	public static readonly DependencyProperty PlaceHolderProperty = DependencyProperty.Register("PlaceHolder", typeof(string), typeof(HeadOptionalTextBox));

	/// <summary>
	/// 下拉框资源
	/// </summary>
	public ObservableCollection<int> TelephoneOwnershipCollection
	{
		get { return (ObservableCollection<int>)GetValue(TelephoneOwnershipCollectionProperty); }
		set { SetValue(TelephoneOwnershipCollectionProperty, value); }
	}

	public static readonly DependencyProperty TelephoneOwnershipCollectionProperty = DependencyProperty.Register("TelephoneOwnershipCollection", typeof(ObservableCollection<int>), typeof(HeadOptionalTextBox), new PropertyMetadata(new ObservableCollection<int>(), OnTelephoneOwnershipCollectionChanged));

	private static void OnTelephoneOwnershipCollectionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
	{
		if (e.NewValue is ObservableCollection<int> newTelephoneOwnershipCollection)
		{
			newTelephoneOwnershipCollection.CollectionChanged += TelephoneOwnershipCollection_CollectionChanged;
		}
		//DoSomething
	}

	private static void TelephoneOwnershipCollection_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
	{
		//DoSomething
	}




	public override void OnApplyTemplate()
	{
		base.OnApplyTemplate();
	
	}

	protected override void OnTextChanged(TextChangedEventArgs e)
	{
		if (this.Text != PlaceHolder)
		{
			base.OnTextChanged(e);
		}
	}
}